import {defineStore} from 'pinia'
import {reqGetBannerList, reqGetCategoryList, reqGetFloorList} from '@/api'
import {BannerType, CategoryType, FloorType} from './types'
//home模块的仓库
export const useHomeStore = defineStore('home', {
    state: () => ({
        //三级菜单
        categoryList: <CategoryType[]>[],
        //轮播图
        bannerList: <BannerType[]>[],
        //floor组件的数据
        floorList: <FloorType[]>[]
    }),
    getters: {},
    actions: {
        //获取三级联动的数据
        async getCategoryList() {
            let result = await reqGetCategoryList()
            if (result.code === 200) {
                this.categoryList = result.data
            }
        },
        //获取首页轮播图的数据
        async getBannerList() {
            let result = await reqGetBannerList()
            if (result.code === 200) {
                this.bannerList = result.data
            }
        },
        //获取floor数据
        async getFloorList() {
            let result = await reqGetFloorList()
            if (result.code === 200) {
                this.floorList = result.data
            }
        }
    }
})
